/**
 * 
 */
package fr.insalyon.sims.broadcast.service;

import java.net.InetAddress;
import java.net.UnknownHostException;

import fr.insalyon.sims.streamManagerClient.ServiceManager;

/**
 * @author nsattayaka
 *
 */
public class BroadcastTransmitterServiceLaunch {

	public static final String SERVER_ADDRESS = "127.0.0.255";
	/**
	 * @param args
	 * @throws UnknownHostException 
	 */
	public static void main(String[] args) throws UnknownHostException {
		// Default parameters values
		int srcPort = 3333;
		int multicastPort = 4242;
		String multicastAddress = "224.0.0.1";
		
		// Command line parameters values
		for (int i = 0; i < args.length; i++) {
			String arg = args[i];
			
			try {
				if (arg.equals("-p") || args.equals("-port"))
					srcPort = Integer.parseInt(args[i + 1]);
				else if (arg.equals("-mip"))
					multicastAddress = args[i + 1];
				else if (arg.equals("-mp") || arg.equals("-mport"))
					multicastPort = Integer.parseInt(args[i + 1]);
			} catch (Exception e) {
				System.out.println("Syntax: java -jar broadcast.jar -p <src_port> -mip <multicast_ip> -mp <multicast_port>");
				System.exit(0);
			}
		}
		
		BroadcastTransmitterService service = new BroadcastTransmitterService(srcPort, InetAddress.getByName(multicastAddress),multicastPort);
		
		ServiceManager sm = ServiceManager.getInstance(service, SERVER_ADDRESS);
		sm.addParameter("multicastIp", multicastAddress);
		sm.addParameter("multicastPort", String.valueOf(multicastPort));
		
		sm.register();
	}
	
	// ------------------------------------------------------- CONSTANTS -- //
	// ------------------------------------------------------ ATTRIBUTES -- //
	// ---------------------------------------------------- CONSTRUCTORS -- //
	// --------------------------------------------------------- METHODS -- //
	// ------------------------------------------------- PRIVATE METHODS -- //
	// --------------------------------------------------- INNER CLASSES -- //
}
